<template>
  <div id="box">
    <h1>点击图片查看效果</h1>
    <div>
      <!-- 图片列表 -->
      <img
        class="imgitem"
        v-for="(i, index) in list"
        :key="index"
        :src="i"
        @click="change(index)"
      />
      <!-- 预览图片 -->
      <Preview v-if="show" :list="list" :index="index" @close="show = false" />
    </div>
  </div>
</template>

<script>
import Preview from "./components/preview.vue";
import img_1 from "./assets/img/img_1.png";
import img_2 from "./assets/img/img_2.png";

export default {
  name: "App",
  components: {
    Preview,
  },
  data() {
    return {
      list: [img_1, img_2],
      show: false,
      index: 0,
    };
  },
  methods: {
    change(index) {
      console.log(index);
      this.show = true;
      this.index = index;
    },
  },
};
</script>

<style>
#box {
  margin-top: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.imgitem {
  width: 200px;
  height: 200px;
  margin: 0 10px;
  object-fit: cover;
  background: rgb(99, 99, 99);
  cursor: pointer;
}
</style>
